﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace Pevolution.GameObjects
{
    public class Critter
    {
        private Vector2 position;
        private Texture2D tex;
        private Game1 game1;

        protected int dir = 0;
        protected bool moving = false;

        public int[,] memory = new int[8, 8];

        public int energy;

        public Critter(Vector2 position, Texture2D tex, Game1 game1)
        {
            this.position = position;
            this.tex = tex;
            this.game1 = game1;

            energy = 0;
        }

        public void Update(List<Food> foodz)
        {
            position.Y += 2f;
            foreach(Food food in foodz){
                if (new Rectangle((int)position.X, (int)position.Y, 8, 8).Intersects(new Rectangle((int)food.getPosition().X, (int)food.getPosition().Y, 8, 8)) && !food.dead)
                {
                    this.energy += food.energy;
                    food.SetPossition(food.getPosition().X, food.getPosition().Y - 8);
                    //food.dead = t
                }
            }

            if (energy >= 11)
            {
                game1.creatures.Add(new Critter(new Vector2(getPosition().X, getPosition().Y - 10), tex, game1));
                energy -= 10;
            }
        }

        public Vector2 getPosition()
        {
            return position;
        }

        public void SetPossition(float x, float y)
        {
            position = new Vector2(x, y);
        }

        public void Render(SpriteBatch sb, float rotation, float scale, Color c)
        {
            sb.Draw(tex, position, null, c, rotation, Vector2.Zero, scale, SpriteEffects.None, 0); 
        }
    }
}
